﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using MagicalDesktop.Simulation;

namespace MagicalDesktop
{
    /// <summary>
    /// Interaction logic for RecentMessage.xaml
    /// </summary>
    public partial class RecentMessage : UserControl
    {
        public RecentMessage()
        {
            this.DataContext = null;

            InitializeComponent();
            Shell.Instance.UserButtonClicked = OnUserButtonClicked;

            _allTab.DataContext = Shell.Instance.Groups;
            foreach (var group in Shell.Instance.Groups)
            {
                if (group.Name == "Friends")
                    _friendsTab.DataContext = group;
                else if (group.Name == "Family")
                    _familyTab.DataContext = group;
                else if (group.Name == "Classroom")
                    _classroomTab.DataContext = group;
            }
        }

        private void OnUserButtonClicked(User user)
        {
            switch (user.Group)
            {
                case "Friends":
                    _friendsTab.IsSelected = true;
                    break;
                case "Family":
                    _familyTab.IsSelected = true;
                    break;
                case "Classroom":
                    _classroomTab.IsSelected = true;
                    break;
            }

            _onlineUserDetails.DataContext = user;
            _offlineUserDetails.DataContext = user;

            if (user.IsOnline)
            {
                _onlineUserDetails.Visibility = Visibility.Visible;
                _offlineUserDetails.Visibility = Visibility.Collapsed;
            }
            else
            {
                _onlineUserDetails.Visibility = Visibility.Collapsed;
                _offlineUserDetails.Visibility = Visibility.Visible;
            }
        }
    }
}
